home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
033a
/
maxjm110.zip
/
MAXJM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-05-20
|
7KB
|
164 lines
/*[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*]
[*] [*]
[*] [*]
[*] MaxJM -- a program to run the JModem protocol for the Maximus BBS. [*]
[*] Version -- 1.10 [*]
[*] [*]
[*] [*]
[*] Written by Ray Kaliss of FidoNet 1:141/840. [*]
[*] Later hacked on and modified by Randy Edwards. [*]
[*] [*]
[*] [*]
[*] Command line parameters: none [*]
[*] [*]
[*] [*]
[*] Errorlevels returned: [*]
[*] [*]
[*] 255 = Bad parameter passed in a case statement. Programmer's [*]
[*] error that should never happen. [*]
[*] [*]
[*] 254 = Error reading MaxJM.CTL file created by Maximus/Opus. [*]
[*] Unlikely to happen. [*]
[*] [*]
[*] 253 = Unspecified error while doing the DOS shell. Out of [*]
[*] memory probably, couldn't find COMSPEC variable, etc. [*]
[*] [*]
[*] 252 = Error opening MaxJM.CTL file -- i.e. file not found. [*]
[*] [*]
[*] 1 = Everything went okay except the file transfer aborted. [*]
[*] [*]
[*] 0 = All successful. Successful shell to JMBatch.* done. [*]
[*] [*]
[*] [*]
[*] Compiler: Turbo C 2.01 Compiler switches: nothing special [*]
[*] [*]
[*] [*]
[*] Program/compiling/library notes: none [*]
[*] [*]
[*] [*]
[*] Bugs/known problems/deficiencies: Could use comprehensive error [*]
[*] checking on all file operations. [*]
[*] [*]
[*] [*]
[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*]*/
#include <dir.h>
#include <process.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
main()
{
FILE *InputFileStream;
char xload[80], xfer[10];
char tsend[10] = "Send", tget[10] = "Get ";
puts("\r\nMax-JModem: an external JMODEM file transfer interface program for Max/Opus.");
puts("Written by Ray Kaliss of 1:141/840, hacked on by Randy Edwards.\r\n");
if ((InputFileStream = fopen("maxjm.ctl", "r")) == NULL) {
puts("Error: Control file MAXJM.CTL not found.");
getout(252);
}
fgets(xload, 80, InputFileStream);
fgets(xload, 80, InputFileStream);
fgets(xload, 80, InputFileStream);
fgets(xload, 80, InputFileStream);
fgets(xload, 80, InputFileStream);
fgets(xload, 80, InputFileStream);
fgets(xload, 9, InputFileStream);
fgets(xload, 80, InputFileStream);
fgets(xload, 80, InputFileStream);
fgets(xload, 80, InputFileStream);
fgets(xfer, 5, InputFileStream); /* fgets the 'Send' or 'Get' */
fgets(xload, 80, InputFileStream); /* Advance down to the next line */
fgets(xload, 4, InputFileStream);
fgets(xload, 30, InputFileStream);
fclose(InputFileStream);
if (strncmpi(tsend, xfer, 3) == 0) { /* If it's a "Send" ... */
getout(do_it(xload, 'S'));
}
else if (strncmpi(tget, xfer, 3) == 0) { /* If it's a 'Get' ... */
getout(do_it(xload, 'G'));
}
else { puts("Error: Unable to properly read MAXJM.CTL file.");
getout(254);
}
/* We should never hit the below line. */
return(0);
} /* End of function main() */
/*------------------------------ Functions -------------------------------*/
/* do_it -- a function to do the actual shell, check for an aborted transfer
and to write out the MAXJM.LOG log file. */
int do_it(filename, get_send)
char get_send;
char filename[80];
{
FILE *OutputFileStream;
struct ffblk ffblock;
struct stat filestats;
char fdrive[MAXDRIVE], fdir[MAXDIR], fname[MAXFILE], fext[MAXEXT];
char command[80], log_line[10];
char flagfile[] = "MAXJM.FLG";
int found, errflag;
errflag = 0;
switch (toupper(get_send)) {
case 'G': strcpy(command, "JMBatch R ");
strcat(command, filename);
strcpy(log_line, "Got ");
break;
case 'S': strcpy(command, "JMBatch S ");
strcat(command, filename);
strcpy(log_line, "Sent ");
break;
default:
puts("Bad parameter passed as get_send.");
getout(255);
break;
}
printf("Shelling out to JMBATCH: %s ", command);
if (system(command) != 0) /* If the shell was bad set errflag. */
errflag = 253;
found = findfirst(flagfile, &ffblock, 0); /* Check for flag-file. */
if (found == 0) { /* If we find the flag file, erase it */
unlink(flagfile); /* because it was a bad file xfer. */
errflag = 1; /* Set errorflag for an aborted transfer. */
}
else if (errflag == 0) { /* The shell was successful + no flag-file. */
filename[strlen(filename)-1] = '\0'; /* Zap the \n on string filename. */
if (stat(filename, &filestats) != 0)
filestats.st_size = 100000; /* If we don't know the size, use 100k. */
fnsplit(filename, fdrive, fdir, fname, fext);
strcpy(filename, fname); /* Break filename down into only NAME.EXT. */
strcat(filename, fext);
OutputFileStream = fopen("maxjm.log", "w"); /* Write it out ... */
fprintf(OutputFileStream, "%s%s %i\r\n", log_line, filename, filestats.st_size);
fprintf(OutputFileStream, " file\r\n"); /* Is this line needed?! */
fclose(OutputFileStream);
}
return(errflag);
}
/* getout -- a general exit-with-errorlevel function. */
int getout(int errorlevel)
{
fcloseall();
printf("\n\rMax-JModem ending with errorlevel %i.\n\r", errorlevel);
exit(errorlevel);
return(0);
}